//
//  SCClass.swift
//  scfriend
//
//  Created by wulanzhou on 2017/7/21.
//  Copyright © 2017年 wulanzhou. All rights reserved.
//

import Foundation
import SwiftyJSON

class SCClass: NSObject {
    
    var class_id:String?
    var create_at:String?
    var desc:String?
    var grade:String?
    var icon:String?
    var name:String?
    var parent_prdfix:String?
    var school_code:String?
    var school_name:String?
    var status:String?
    
    var studentNum:String?
    var teacher_id:String?
    
    var subjects:[SCCourse]?
    
    func mapper(map:Dictionary<String, JSON>)  {
        
        
        if let item = map["class"]?.dictionary {
            
            self.class_id = item["class_id"]?.rawString()
            self.create_at = item["create_at"]?.rawString()
            self.desc = item["description"]?.rawString()
            self.grade = item["grade"]?.rawString()
            self.icon = item["icon"]?.rawString()
            self.name = item["name"]?.rawString()
            self.parent_prdfix = item["parent_prdfix"]?.rawString()
            self.school_code = item["school_code"]?.rawString()
            self.school_name = item["school_name"]?.rawString()
            self.status = item["status"]?.rawString()
            
            
        }
        
        self.studentNum = map["studentNum"]?.rawString()
        self.teacher_id = map["teacher_id"]?.rawString()
        
        
        
        if let coursses = map["subjects"]?.array {
            
            let mut:NSMutableArray = NSMutableArray.init(capacity: 0)
            
            for item in coursses {
            
                if let dic = item.dictionary{
                  
                    let entity:SCCourse = SCCourse()
                    entity.mapper(map: dic)
                    mut.add(entity)
                }
            }
            
            if mut.count > 0 {
                self.subjects = mut as? [SCCourse]
            }
            
            
        }
        
    }
    
}
